﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class EmailInvitation : IValidatableObject, IAggregateRoot
    {
        public int ID { get; set; }

        [StringLength(25, ErrorMessage = "最大长度为25")]
        [Required(ErrorMessage = "账户不允许为空")]
        //[RegularExpression(@"^[a-zA-Z][a-zA-Z0-9_]{6,15}$", ErrorMessage = "昵称允许数字，字母和下划线")]
        public string AccountName { get; set; }

        [Required(ErrorMessage = "请选择正确的用户")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的用户编号！")]
        public int UserID { get; set; }


        [Required(ErrorMessage = "邮箱地址不能为空")]
        [StringLength(25, ErrorMessage = "最大长度为25")]
        [RegularExpression(@"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$", ErrorMessage = "请输入正确的电子邮箱地址！")]
        public string Email { get; set; }
        public string Content { get; set; }

        [Required(ErrorMessage = "请选择正确的活动")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的活动编号！")]
        public int PartyID { get; set; }

         [StringLength(30, ErrorMessage = "最大长度为30")]
        public string PartySubject { get; set; }

        public bool IsSent { get; set; }
        public System.DateTime SendDate { get; set; }


        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(UserID.ToString()))
            {
                yield return new ValidationResult("用户不允许为空!");
            }

            if (string.IsNullOrEmpty(Email))
            {
                yield return new ValidationResult("邮件地址不允许为空！");
            }
        }
    }
}
